package com.usercar.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dk.bean.Result;
import com.dk.em.ResultEnum;
import com.usercar.pojo.Festival;
import com.usercar.service.IFestivalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-11
 */
@RestController
@RequestMapping("/festival")
@Api("日期统一接口文档")
public class FestivalController {

    @Autowired
    private IFestivalService iFestivalService;

    @ApiOperation(value = "日期的增加")
    @PostMapping
    public Result toInsert(@RequestBody Festival festival){
        Integer i = iFestivalService.toInsert(festival);
        if(i>0){
            return Result.buildResult(ResultEnum.SUCCESS);
        }else {
            return Result.buildResult(ResultEnum.ERROR);
        }
    }
    @ApiOperation(value = "根据id回显")
    @GetMapping(value = "/{festivalId}")//@RequestParam java中的数据类型如string 加上此注解表名参数为必填项 //@RequestBody  就收实体类要求前台必须用json的格式传参
    public Result selectById(@PathVariable("festivalId") Long festivalId) {
       Festival festival =  iFestivalService.selectById(festivalId);
            return Result.buildResult(ResultEnum.SUCCESS).setData(festival);
    }

    @ApiOperation(value = "根据id进行修改")
    @PutMapping
    public Result updateFestivalById(@RequestBody Festival festival){
        int i = iFestivalService.updatefestivalId(festival);
        if(i>0){
            return Result.buildResult(ResultEnum.SUCCESS);
        }else {
            return Result.buildResult(ResultEnum.ERROR);
        }
    }

    @ApiOperation(value = "根据id删除一行")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable(value = "id")Integer festivalId){
        Integer i = iFestivalService.deleteById(festivalId);
        if(i>0){
            return Result.buildResult(ResultEnum.SUCCESS);
        }else {
            return Result.buildResult(ResultEnum.ERROR);
        }
    }

    @ApiOperation("分页查询")
    @GetMapping(value = "/{pageNum}/{pageSize}")
    public Result selectAll(@PathVariable(value = "pageNum")Integer pageNum,@PathVariable("pageSize")Integer pageSize){
        Map<String,Object> map = iFestivalService.selectByPage(pageNum,pageSize);
        return Result.buildResult(ResultEnum.SUCCESS).setData(map);
    }
}

